#include <stdio.h>

#include "SocketUtils.h"
#include "Log.h"

int	main(int argc, char **argv) {
    char buffer[100] = "123456";

    UdpSocket socket = {0};
    UdpSocketOrigin origin = {0};
    // setSocketOriginConnectAddress(&origin, AF_INET, "127.0.0.1", 8080);

    if (createUdpSocketWithHostPort(&socket, &origin, "127.0.0.1", 8080)) {
        // createUdpSocket(&socket);
        WARNING_LOG("连接成功");
    
        int len = 0;
        len = udpSocketWrite(&socket, buffer, sizeof(buffer), &origin);
        INFO_LOG("send: len: %d: %s", len, buffer);

        len = udpSocketWrite(&socket, buffer, sizeof(buffer), &origin);
        INFO_LOG("send: len: %d: %s", len, buffer);

        len = udpSocketRead(&socket, buffer, 100, &origin);
        INFO_LOG("receiver: len: %d: %s", len, buffer);

    } else {
        WARNING_LOG("连接失败");
    }
    return 0;


    // //创建socket对象
    // // int sockfd=socket(AF_INET,SOCK_DGRAM,0);

    // UdpSocket socket = {0};
    // // createUdpSocket(&socket);


    // //创建网络通信对象
    // // struct sockaddr_in addr;
    // // addr.sin_family =AF_INET;
    // // addr.sin_port =htons(1324);
    // // addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    // UdpSocketOrigin origin = {0};
    // // setSocketOriginConnectAddress(&origin, AF_INET, "127.0.0.1", 1324);

    // createUdpSocketWithHostPort(&socket, &origin, "127.0.0.1", 1324);

    // char buffer[100] = "Hello World!";
    // // scanf("%c",&buf);
    // // sendto(sockfd,&buf, sizeof(buf),0,(struct sockaddr*)&addr,sizeof(addr));
    // udpSocketWrite(&socket, buffer, sizeof(buffer), &origin);
    // printf("send val = %s\n",buffer);

    // // socklen_t len=sizeof(addr);
    // udpSocketRead(&socket, buffer, sizeof(buffer), &origin);
    // // recvfrom(socket.socket,buffer, sizeof(buffer),0,(struct sockaddr*)&origin.address,&origin.address_len);
    // // udpSocketRead(&socket, buffer, sizeof(buffer), &origin);
    // printf("recv val = %s\n",buffer);

}